<?php

include_once 'Classes/PHPCodeProvider.php';

/*
 * Create the class
 */

$combination = new TypeDeclaration('Combination');

/*
 * Create class constructor with a parameter named 'first'
 */

$parameters = new ParameterDeclarationExpressionCollection();
$parameters->add(new ParameterDeclarationExpression('first'));

$constructor = new Method('__construct', $parameters);

/*
 * $first refers to a constructor argument named '$first'
 * It can be used to reference the argument while
 * generating the constructor statements.
 */

$first = new ArgumentReferenceExpression('first');

/*
 * Use $first as the right part of an assign statement
 */

$assignStatement = new AssignStatement(
    new FieldReferenceExpression('first', 
        new ThisReferenceExpression()), $first);

$constructor->Statements->add($assignStatement);

$combination->Methods->add($constructor);

/*
 * Generate the constructor code 
 */

$options = new CodeGeneratorOptions();
$writer = new IndentedTextWriter();

$provider = new PHPCodeProvider();
$provider->generateCodeFromType($combination, $writer, $options);

echo '<pre>' . 
    str_replace('<br />', '', highlight_string($writer->get_String(), true)) 
        . '<pre/>';

/*
 * The output should be:
 * 
 * class Combination 
 * {
 *   
 *   public function __construct ($first)
 *   {
 *       $this->first = $first;
 *   }
 * }
 * 
 */

?>
